#include<iostream>
using namespace std;

int arr[110][110];
int m, n;

int main()
{
	cin >> m >> n;
	int sum = 0;
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> arr[i][j];
			if (i == 0 || j == 0 || i == m - 1 || j == n - 1)
				sum += arr[i][j];
		}
	}
	cout << sum << endl;
	
	return 0;
}
